package com.jiai.live.controller;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.jiai.core.tools.RestResultGenerator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import com.jiai.exception.ServiceException;
import com.jiai.live.service.LiveGiftService;
import com.jiai.live.model.LiveGiftSearch;
import com.jiai.live.model.LiveGift;


/** 
 * 说明：
 * 创建人：小方工作室
 * 创建时间：2017-05-07
 */
@Controller
@RequestMapping(value="/livegift")
public class LiveGiftController {
	protected Logger logger = LoggerFactory.getLogger(this.getClass());
	
	@Autowired
	private LiveGiftService livegiftService;
	
	
	
	@RequestMapping(value="/del",method=RequestMethod.GET, produces = {"application/json;charset=UTF-8"})
	@ResponseBody
	public Object delete(Long id)throws ServiceException{
		    try{
				livegiftService.delete(id);
				return RestResultGenerator.genSuccessResult();
			}catch(Exception e){
			  throw new ServiceException("删除失敗", e.getMessage());
			}
	}
	@RequestMapping(value="/edit",method=RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
	@ResponseBody
	public Object edit(LiveGift livegift)throws ServiceException{
		try {
			if(livegift.getId()==null){
				livegiftService.save(livegift);
			}else{
				livegiftService.update(livegift);
			}
			return RestResultGenerator.genSuccessResult();
		} catch (Exception e) {
			throw new  ServiceException("编辑失敗",e.getMessage());
		}
	}
	
	/**
	 * 模糊查詢不分頁
	 * @param search
	 * @return
	 * @throws ServiceException
	 */
	@RequestMapping(value="/findByAll", method=RequestMethod.POST,produces = {"application/json;charset=UTF-8"})
	@ResponseBody
	public Object findByParams(LiveGiftSearch search ) throws ServiceException{
		try{
			
			return RestResultGenerator.genSuccessResult(livegiftService.findByParams(search));
		}catch (Exception e) {
			throw new  ServiceException("查询失败",e.getMessage());
		}
	}
	
	/**
	 * 模糊查詢幷分頁
	 * @param search
	 * @return
	 * @throws ServiceException
	 */
	@RequestMapping(value="/findByPage",method=RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
	@ResponseBody
	public Object findByPage(LiveGiftSearch search ) throws ServiceException{
		try{
			
			return RestResultGenerator.genSuccessResult(livegiftService.findByPage(search));
		}catch (Exception e) {
			throw new  ServiceException("查询失败",e.getMessage());
		}
	}
	
	
}